package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.enums.EnableStatusEnum;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * 区域服务管理相关接口(给运营管理人员使用)
 * @author DragonflyYue
 * 写代码之前要先参考别人写的代码的风格形式
 */
@RestController("operationServeController") 
@RequestMapping("/operation/serve")
@Api(tags = "运营端-区域服务管理相关接口")
public class ServeController {
    @Resource
    private IServeService serveService;
    
    //接口路径:   GET/foundations/operation/serve/page
    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        
        return serveService.page(servePageQueryReqDTO);
    }
     
    @PostMapping("/batch")
    @ApiOperation("添加区域服务")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList) {
        serveService.batchAdd(serveUpsertReqDTOList);
    }
    
    @PutMapping("/{id}")
    @ApiOperation("修改区域服务价格")
    @ApiImplicitParams({   //这个注解是为了让生成的接口文档参数,保持一致,,就相当于一个说明;以前没用过,,,,直接复制不用手敲
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
    })
    public void update(@PathVariable Long id, BigDecimal price) {
        //虽然这里把主键id传递回来了,,但是我记得在苍穹外卖的时候,,是可以通过工具类获取用户id的;好吧前端传也完全没问题
        
        serveService.update(id, price);
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public void onSale(@PathVariable("id") Long id) {
        serveService.onSale(id);
    }


    @DeleteMapping("/{id}")
    @ApiOperation("区域服务删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public void deleteRegionServe(@PathVariable("id") Long id) {
        serveService.deleteRegionServe(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public void offSale(@PathVariable("id") Long id) {
        serveService.offSale(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation("区域服务设置热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public void onHot(@NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        //这里就直接用@NotNull来验证了,要不serviceImpl总得单独验证一遍是否为null,太麻烦了
        //老师这里优化了代码,,,只修改传入的热门状态,,就不用单独在写一个方法实现"取消热门了"
        serveService.changeHotStatus(id, EnableStatusEnum.ENABLE.getStatus());
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("区域服务取消热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public void offHot(@NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        //这里就直接用@NotNull来验证了,要不serviceImpl总得单独验证一遍是否为null,太麻烦了

        //老师这里优化了代码,,,只修改传入的热门状态,,就不用单独在写一个方法实现"取消热门了"
        serveService.changeHotStatus(id,EnableStatusEnum.DISABLE.getStatus());
    }
}
